﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Xml;

namespace SolutionOrchestrator.Validators
{
	public abstract class XmlFileValidator : IFileValidator
	{
		protected abstract IEnumerable<Violation> Validate(XmlDoc doc, ValidationContext ctx);

		protected virtual bool NeedValidate(string file)
		{
			return true;
		}

		#region Implementation of IFileValidator

		public IEnumerable<Violation> Validate(string file, ValidationContext ctx)
		{
			if (NeedValidate(file))
			{
				var doc = new XmlDoc(file);
				foreach (var violation in Validate(doc, ctx))
				{
					yield return violation;
				}
			}
		}

		public string Name
		{
			get { return GetType().Name; }
		}

		bool _isEnabled = true;
		public bool IsEnabled
		{
			get { return _isEnabled; }
			set { _isEnabled = value; }
		}

		#endregion
	}
}